package com.nxy.cpfsfe;

import com.nxy.cpfsfe.util.DateUtil;
import com.nxy.cpfsfe.util.FileUtil;
import org.junit.Test;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class FileCreatTest_zhun {

	/**
	 * 获取指定位数的流水信息
	 * @param seqNo
	 * @param size
     * @return
     */
    public  String getSeqNo(String seqNo, int size) {
        while (seqNo.length() < size) {
            seqNo = "0" + seqNo;
        }
        return seqNo;
    }
	@Test
	public void creatFile(){
		List<String> list = new ArrayList<String>();
		String datestr = DateUtil.getDate();
		String timestr = DateUtil.getTime();
		String time = datestr+timestr;
		String seqno = time+"0001";
		int num  = 2;
		float amt =800000;
		float nowamt =amt/num;
//		BigDecimal amt =new BigDecimal("5000");
//		BigDecimal nowamt =amt.;
		String first = seqno+"|110001|"+datestr+"|"+num+"|"+amt+"|"+DateUtil.getDate()+"|"+timestr;
		list.add(first);
		for (int i=1;i<=num;i++) {
			String detail = "20200708"+"0001"+getSeqNo(String.valueOf(i), 6)+"|1|"+seqno+"|MP|110001|120001|"
					+ "402221010048||||402121000308||||"+nowamt+"|||"+i;
			list.add(detail);
		}
		String name = seqno+".txt";
		String path="C:\\Users\\nxygyzd\\Desktop\\测试文件\\"+datestr+"\\"+name;
		try {
			FileUtil.writeFile(path, list);
		} catch (Exception e) {
			// TODO 自动生成的 catch 块
			e.printStackTrace();
		}
		String msg = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><root><MsgHeader><TrxId>"

//		String msg = "<?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?><root><MsgHeader><TrxId>"
				+ seqno
				+ "</TrxId><CorrId>"

				+ seqno
				+ "</CorrId><SndSysId>NGPS</SndSysId><RcvBankId>402121000308</RcvBankId><SndBankId>402221010048</SndBankId>"
				+ "<SndDt>"+DateUtil.date2Str(new Date())+"</SndDt>"
				+ "<RcvSysId>NCS</RcvSysId><Drctn>21</Drctn><MsgTp>CPFS.108.001.01</MsgTp><ClbckUrl>http://172.16.26.48:8090/serviceController/autoAmountGatherNotify.do</ClbckUrl></MsgHeader>"
				+ "<MsgBody><StlSumInfo>"
				+ "<FileCreD>"+datestr+"</FileCreD>"
				+ "<FileCreT>"+timestr+"</FileCreT>"
				+ "<BStlTotDN>"+num+"</BStlTotDN>"
				+ "<BatNo>"+seqno+"</BatNo>"
				+ "<MerId>110001</MerId>"
				+ "<BStlTotAmt>"+amt+"</BStlTotAmt>"
				+ "<StlD>"+datestr+"</StlD></StlSumInfo>"
				+ "<FileNm>"+name+"</FileNm>"
				+ "</MsgBody></root>";
		System.out.println(msg);
	}

}
